package com.mytech.cslive.commands;

import com.mytech.cslive.Player;
import com.mytech.cslive.PlayerStatus;

public class PlayerDataCommand extends Command {
	private final static String NAME = "PlayerDataCommand";
	private final static String PROPERTY_LOCATION = "Location";
	private final static String PROPERTY_STATUS = "Status";
	private final static String PROPERTY_SPAWN_POINT_SECONDS_LEFT = "SecondsLeft";
	
	private Player player;
	
	public PlayerDataCommand(Player player) {
		super(NAME);
		
		this.player = player;
	}
	
	public static String getPropertyLocation() {
		return PROPERTY_LOCATION;
	}

	public static String getPropertyStatus() {
		return PROPERTY_STATUS;
	}

	public static String getPropertySpawnPointSecondsLeft() {
		return PROPERTY_SPAWN_POINT_SECONDS_LEFT;
	}
	
	public Player getPlayer() {
		return player;
	}
	
	@Override
	public String toString() {
		String playerData = super.toString();
		
		// Player location
		CommandParameter location = new CommandParameter(getPropertyLocation(), 
				 Double.toString(this.getPlayer().getCurrentLocation().x),
				 Double.toString(this.getPlayer().getCurrentLocation().y));
		
		// Player status
		CommandParameter status = new CommandParameter(getPropertyStatus(), 
				 this.getPlayer().getStatus().toString());
		
		// Check if player is in spawn point
		if (this.getPlayer().getStatus().equals(PlayerStatus.IN_SPAWN_POINT)) {
			// Add seconds left parameter
			CommandParameter spawnPointSecondsLeft = new CommandParameter(
					getPropertySpawnPointSecondsLeft(), 
					Integer.toString(this.getPlayer().getSpawnPointSecondsLeft()));
			
			// Add location, status and seconds left
			playerData = super.addParameters(playerData, location, 
					status, spawnPointSecondsLeft);
		} else {
			// Add location and status
			playerData = super.addParameters(playerData, location, status);
		}
		
		return (super.addEndDelimeter(playerData));
	}
}
